<?php

namespace app\home\controller;

use app\common\controller\ApiController;
use app\home\service\ApiService;
use think\Db;

class Api extends ApiController
{
    /**
    * 首页
    */
    public function home()
    {
        $result = ApiService::home();
        return json($result);
    }

    /**
    * 广告详细页
    */
    public function adv_article()
    {
        $id = input('get.id');
        $home_adv = Db::name('home_adv')->where('id', $id)->find();
        $this->assign('article', $home_adv);
        return view('Article/article');
    }

    /**
    * 轮播图详细页
    */
    public function image_article()
    {
        $id = input('get.id');
        $home_image = Db::name('home_image')->where('id', $id)->find();
        $this->assign('article', $home_image);
        return view('Article/article');
    }

    /**
    * 注册站点列表
    */
    public function register_station_list()
    {
        $address = input('address');
        $result = ApiService::register_station_list($address);
        return json($result);
    }

    /**
    * 会员注册
    */
    // public function member_register()
    // {
    //     $invite_code = input('invite_code');
    //     $station_id = input('station_id');
    //     $phone = input('phone');
    //     $code = input('code');
    //     $password = input('password');
    //     $repetition = input('repetition');
    //     $member_name = input('member_name');
    //     $card_number = input('card_number');
    //     $file1 = request()->file('file1');
    //     $file2 = request()->file('file2');
    //     $sell_phone = input('sell_phone');
    //     $result = ApiService::member_register($invite_code, $station_id, $phone, $code, $password, $repetition, $member_name, $card_number, $file1, $file2, $sell_phone);
    //     return json($result);
    // }

    /**
    * 会员注册
    */
    public function member_register()
    {
        $sell_phone = input('sell_phone');
        $phone = input('phone');
        $code = input('code');
        $password = input('password');
        $repetition = input('repetition');
        $member_name = input('member_name');
        $result = ApiService::member_register($sell_phone, $phone, $code, $password, $repetition, $member_name);
        return json($result);
    }

    /**
    * 用户密码登录
    */
    public function member_login()
    {
        $phone = input('phone');//手机号
        $password = input('password');//密码
        $result = ApiService::member_login($phone, $password);
        return json($result);
    }

    /**
    * 用户退出
    */
    public function member_logout()
    {
        $token = input('token');
        $result = ApiService::member_logout($token);
        return json($result);
    }

    /**
    * 手机验证码登录
    */
    public function phone_login()
    {
        $phone = input('phone');
        $code = input('code');
        $result = ApiService::phone_login($phone, $code);
        return json($result);
    }

    /**
    * 忘记密码
    */
    public function forget_pass()
    {
        $phone = input('phone');
        $code = input('code');
        $newpassword = input('newpassword');
        $repassword = input('repassword');
        $result = ApiService::forget_pass($phone, $code, $newpassword, $repassword);
        return json($result);
    }

    /**
    * 修改绑定手机,验证旧手机
    */
    public function change_old_phone()
    {
        $token = input('token');
        $old_phone = input('old_phone');
        $code = input('code');
        $result = ApiService::change_old_phone($token, $old_phone, $code);
        return json($result);
    }

    /**
    * 修改绑定手机,验证新手机
    */
    public function change_new_phone()
    {
        $token = input('token');
        $newphone = input('newphone');
        $code = input('code');
        $result = ApiService::change_new_phone($token, $newphone, $code);
        return json($result);
    }

    /**
    * 会员修改头像
    */
    public function member_upload_img()
    {
        $token = input('token');
        $file = request()->file('file');
        $result = ApiService::member_upload_img($token, $file);
        return json($result);
    }

    /** 
    * 修改昵称
    */
    public function change_member_name()
    {
        $token = input('token');
        $nick_name = input('nick_name');
        $result = ApiService::change_member_name($token, $nick_name);
        return json($result);
    }

    /**
    * 发送手机验证码
    */
    public function send_code()
    {
        $phone = input('phone');//手机号
        $type = input('type');//类型：1=注册，2=登录，3=忘记密码，4=修改手机号
        $result = ApiService::send_code($phone, $type);
        return json($result);
    }

    /**
    * 修改密码
    */
    public function change_pass()
    {
        $token = input('token');
        $old_pass = input('old_pass');
        $new_pass = input('new_pass');
        $re_pass = input('re_pass');
        $result = ApiService::change_pass($token, $old_pass, $new_pass, $re_pass);
        return json($result);
    }

    /**
    * 租车页面
    */
    public function create_order()
    {
        $token = input('token');
        $result = ApiService::create_order($token);
        return json($result);
    }

    /**
    * 租车页面计算价格
    */
    public function compute_price()
    {
        $token = input('token');
        $rent_id = input('rent_id');
        $result = ApiService::compute_price($token, $rent_id);
        return json($result);
    }

    /**
    * 提交订单
    */
    public function commit_order()
    {
        $token = input('token');
        $rent_id = input('rent_id');
        $result = ApiService::commit_order($token, $rent_id);
        return json($result);
    }

    /**
    * 支付
    */
    public function pay_order()
    {
        $token = input('token');
        $order_sn = input('order_sn');
        $payment_code = input('payment_code');
        $result = ApiService::pay_order($token, $order_sn, $payment_code);
        return json($result);
    }

    /**
    * 微信支付回调
    */
    public function wxpayNotify()
    {
        $result = ApiService::wxpayNotify();
    }

    /**
    * 支付宝回调
    */
    public function aliPayBack()
    {
        $result = ApiService::aliPayBack();
    }

    /**
    * 判断业务是否正确
    */
    public function judge_rent()
    {   
        $token = input('token');
        $type1 = input('type1');
        $type2 = input('type2');
        $result = ApiService::judge_rent($token, $type1, $type2);
        return json($result);
    }

    /**
    * 租车还车上传图片
    */
    public function rent_image()
    {   
        $token = input('token');
        $order_id = input('order_id');
        $type = input('type');
        $card_number = input('card_number');
        $name1 = input('name1');
        $name2 = input('name2');
        $name3 = input('name3');
        $name4 = input('name4');
        $name5 = input('name5');
        $name6 = input('name6');
        $name7 = input('name7');
        $name8 = input('name8');
        $name9 = input('name9');
        $name10 = input('name10');
        $name11 = input('name11');
        $name12 = input('name12');
        $remark = input('remark');
        $file = request()->file('file');
        $result = ApiService::rent_image($token, $order_id, $type, $card_number, $name1, $name2, $name3, $name4, $name5, $name6, $name7, $name8, $name9, $name10, $name11, $name12, $remark, $file);
        return json($result);
    }

    /**
    * 小哥发布修改信息
    */
    public function create_article()
    {   
        $token = input('token');
        $content = input('content');
        $name = input('name');
        $phone = input('phone');
        $file = request()->file('file');
        $type = input('type');
        $article_id = input('article_id');
        $result = ApiService::create_article($token, $content, $name, $phone, $file, $type, $article_id);
        return json($result);
    }

    /**
    * 小哥发布信息列表
    */
    public function article_list()
    {
        $token = input('token');
        $page = input('page');
        $result = ApiService::article_list($token, $page);
        return json($result);
    }

    /**
    * 删除信息
    */
    public function del_article()
    {
        $token = input('token');
        $article_id = input('article_id');
        $result = ApiService::del_article($token, $article_id);
        return json($result);
    }

    /**
    * 订单列表
    */
    public function order_list()
    {
        $token = input('token');
        $page = input('page');
        $result = ApiService::order_list($token, $page);
        return json($result);
    }

    /**
    * 删除订单
    */
    public function del_order()
    {
        $token = input('token');
        $order_id = input('order_id');
        $result = ApiService::del_order($token, $order_id);
        return json($result);
    }

    /**
    * 取消订单
    */
    public function cancel_order()
    {
        $token = input('token');
        $order_id = input('order_id');
        $result = ApiService::cancel_order($token, $order_id);
        return json($result);
    }

    /**
    * 订单详情
    */
    public function order_detail()
    {
        $token = input('token');
        $order_id = input('order_id');
        $result = ApiService::order_detail($token, $order_id);
        return json($result);
    }

    /**
    * 会员是否交押金
    */
    public function if_cash()
    {
        $token = input('token');
        $result = ApiService::if_cash($token);
        return json($result);
    }

    /**
    * 交押金
    */
    public function create_cashorder()
    {
        $token = input('token');
        $order_id = input('order_id');
        $result = ApiService::create_cashorder($token, $order_id);
        return json($result);
    }

    /**
    * 押金支付
    */
    public function pay_cash()
    {
        $token = input('token');
        $order_sn = input('order_sn');
        $payment_code = input('payment_code');
        $result = ApiService::pay_cash($token, $order_sn, $payment_code);
        return json($result);
    }

    /**
    * 微信回调
    */
    public function cash_wxnotify()
    {
        $result = ApiService::cash_wxnotify();
    }

    /**
    * 支付宝回调
    */
    public function cash_alinotify()
    {
        $result = ApiService::cash_alinotify();
    }

    /**
    * 租赁到期时间
    */
    public function member_expiration_time()
    {
        $token = input('token');
        $result = ApiService::member_expiration_time($token);
        return json($result);
    }

    /**
    * 用户使用服务协议
    */
    public function member_agreement()
    {
        $member_agreement = Db::name('member_agreement')->find();
        $this->assign('article', $member_agreement);
        return view('Article/agreement');
    }

    /**
    * 租赁协议
    */
    public function member_rental_agreement()
    {
        $rental_agreement = Db::name('rental_agreement')->find();
        $this->assign('article', $rental_agreement);
        return view('Article/agreement');
    }

    /**
    * 站点列表
    */
    public function station_list()
    {
        $address = input('address');
        $result = ApiService::station_list($address);
        return json($result);
    }

    /**
    * 提车点列表
    */
    public function warehouse_list()
    {
        $address = input('address');
        $result = ApiService::warehouse_list($address);
        return json($result);
    }

    /**
    * 订单消息
    */
    public function order_message()
    {
        $token = input('token');
        $num = input('num');
        $page = input('page');
        $result = ApiService::order_message($token, $num, $page);
        return json($result);
    }

    /**
    * 系统消息
    */
    public function system_list()
    {
        $num = input('num');
        $page = input('page');
        $result = ApiService::system_list($num, $page);
        return json($result);
    }

    /**
    * 退车申请
    */
    public function apply_back()
    {
        $token = input('token');
        $order_id = input('order_id');
        $result = ApiService::apply_back($token, $order_id);
        return json($result);
    }

    
}